<?php
declare (strict_types = 1);

namespace app\admin\controller;
use think\Request;
use app\model\Notice as NoticeModel;
use app\exception\HttpExceptions;
class Notice extends AdminAuth
{
    
    public function delete($id) {

        NoticeModel::deleteNotice($id);
        return $this -> result();
    }

    /**
     * 公告顶置
     */
    public function top(Request $request) {
        $data = $request->get(['id','top']);
        NoticeModel::topNotice($data['id'],$data['top']);
        return $this->result();
    }
     /**
     * 发布公告
     */
    public function save(Request $request) {
        $data = $request -> post();
        NoticeModel::saveNotice($data);
        return $this -> result();
    }

     /**
     * 获取公告分页列表
     */

    public function list (Request $request) {
        $data = $request->get(['page','size']);
        if( !isset($data['page'])|| !isset($data['size'])) {
            throw new HttpExceptions('参数不合法');
        }
        $result = NoticeModel::pageList($data['page'],$data['size']);
        return $this->result($result);
    }

    
    public function test() {
        return $this -> result([],200,'测试');
    }
}
